package com.netty.chat.handler;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.netty.chat.PrivateChatRequest;
import com.netty.chat.PublicChatRequest;
import com.netty.chat.service.ChatService;


@Component
public class ChatHandlerImpl{
	
	@Autowired
	private ChatService chatService;

	public void publicChat(String HONOURUSER_ID, byte[] data) {
		try {
			//反序列化
			PublicChatRequest request = new PublicChatRequest();
			request.readFromBytes(data);
			
			//参数校验
			/*if(StringUtils.isEmpty(request.getContext())){
				return Result.ERROR(ResultCode.AGRUMENT_ERROR);
			}*/
			
			//执行业务
			chatService.publicChat(HONOURUSER_ID, request.getContext());
		}catch (Exception e) {
			e.printStackTrace();
		}
		return ;
	}

	public void privateChat(String HONOURUSER_ID, byte[] data) {
		try {
			//反序列化
			PrivateChatRequest request = new PrivateChatRequest();
			request.readFromBytes(data);
			
			//参数校验
			/*if(StringUtils.isEmpty(request.getContext()) || request.getTargetPlayerId() <= 0){
				return Result.ERROR(ResultCode.AGRUMENT_ERROR);
			}*/
			
			//执行业务
			chatService.privateChat(HONOURUSER_ID, request.getTargetHonourusrId(), request.getContext());
		} catch (Exception e) {
			e.printStackTrace();
		}
		return ;
	}
}
